import 'dart:ui';

import 'package:city_pickers/city_pickers.dart';
import 'package:eplorex/models/base_contanst.dart';
import 'package:eplorex/pages/my/profile/ButtonWidget.dart';
import 'package:eplorex/utils/HttpUtil.dart';
import 'package:flutter/material.dart';

import '../../../utils/ColorUtil.dart';


class EditUserGenderPage extends StatefulWidget {
   EditUserGenderPage({super.key,required this.gender,required this.valueChanged});

  ValueChanged valueChanged;
  num? gender;

  @override
  State<EditUserGenderPage> createState() => _EditUserGenderPageState();
}

class _EditUserGenderPageState extends State<EditUserGenderPage> {

  var formKey = GlobalKey<FormState>();
  num? _gender;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: ButtonWidget(
          width: 80,
          height: 50,
          onPressed: () {
            Navigator.pop(context);
          },
          highlightedColor: ColorUtil.hexColor(0xf7f7f7),
          bgColor: ColorUtil.hexColor(0xffffff),
          bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
          enabled: true,
          bgDisableColor: Colors.grey,
          borderRadius: 8.0,
          child: Text(
            "取消",
            textAlign: TextAlign.center,
            softWrap: true,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w500,
              fontStyle: FontStyle.normal,
              color: ColorUtil.hexColor(0xA1A1A1),
              decoration: TextDecoration.none,
            ),
          ),
        ),
        title: Text("编辑名字"),
        actions: [
          ButtonWidget(
            width: 80,
            height: 50,
            onPressed: () {
              Navigator.pop(context);
              _submit(context);
            },
            highlightedColor: ColorUtil.hexColor(0xf7f7f7),
            bgColor: ColorUtil.hexColor(0xffffff),
            bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
            enabled: true,
            bgDisableColor: Colors.grey,
            borderRadius: 8.0,
            child: Text(
              "确定",
              textAlign: TextAlign.center,
              softWrap: true,
              style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w400,
                fontStyle: FontStyle.normal,
                color: ColorUtil.hexColor(0x338FFF),
                decoration: TextDecoration.none,
              ),
            ),
          )
        ],
      ),
      body: Container(
        child: Form(
          key: formKey,
          child: Column(
            // crossAxisAlignment: CrossAxisAlignment.c,
            children: [
              Text("1个月内只可修改一次"),
              Padding(
                padding: EdgeInsets.symmetric(horizontal: 40),
                child: DropdownButtonFormField(
                  alignment: Alignment.topCenter,
                    decoration: InputDecoration(
                      labelText: '选择一个选项',
                    ),
                  items: <String>['男', '女', '未知']
                      .map<DropdownMenuItem<String>>((String value) {
                    return DropdownMenuItem<String>(
                      value: value,
                      child: Text(value),
                    );
                  }).toList(),
                  onChanged: (value) {
                    _gender=Gender.findByDesc(value as String).value ;
                  },
                  validator:(value){
                      if(value==null){
                        return "请选择";
                      }
                      return null;
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _submit(BuildContext context) {
    if (formKey.currentState!.validate()) {
      formKey.currentState!.save();
      HttpUtil.getInstance()
          .post('/api/user/v1/my/profile/edit/gender', data: _gender);
      widget.valueChanged.call(_gender);
    }
  }
}
